// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    count: 0,
    list:[1,2,3,4,5,6,7,8]
  },

  mutations: {
    addCount(state,payload) {
      if(payload) {
        state.count += payload *1
      } else {
        state.count ++
      }
    }
  },

  actions: {
    asyncAdd(context, payload) {
      setTimeout(()=>{
          context.commit('addCount',payload)
      },1000)
    }
  },

  getters: {
    filterList: state=> state.list.filter(item=> item>5),
    setterId: state=> state.setter.id
  },

  modules: {
    user: {
      // namespaced:true,
      state: {
        id:0
      },
      mutations: {
        changeId(state) {
          state.id +=1
        }
      },

      actions: {
        asyncId(context) {
            setTimeout(()=>{
              context.commit('changeId')
            },1000)
        }
      },

      getters: {
        filterId: state=> state.id += 10
      }
    },
    setter: {
      namespaced:true,
      state: {
        id:0,
        age:10
      },
      mutations: {
        changeId(state) {
          state.id +=1
        }
      },

      actions: {
        asyncId(context) {
            setTimeout(()=>{
              context.commit('changeId')
            },1000)
        }
      },

      getters: {
        filterId: state=> state.id += 10
      }
    },

  }

})

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
